import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import foundlove from '../components/foundlove.vue'
import goodlist from '../components/goodslist.vue'
import liannew from '../components/liannew.vue'
import friends from '../views/friends.vue'
import newtail from '../views/newtail.vue'
import { Toast } from 'vant'
import store from '../store/index'
const routes = [
  {
    path:"/",
    redirect:"index"
  },
  {
    path: '/index',
    name: 'Home',
    component: Home,
    meta:{
      title:'首页',
      isbackshow:false,
      pageshow:false,
      search:true

    },
    children:[{
      path:"/index/search",
      name:'masksearch',
      component: ()=>import ('@/components/mask.vue')
    }]
  },
  {
    path: '/login',
    name: 'Login',
    component: ()=>import ('@/views/login.vue'),
    meta:{
      title:'登录',
      isbackshow:true,
      pageshow:false,
      search:false

    }
  },
  {
    path: '/register',
    name: 'register',
    component: ()=>import ('@/views/register.vue'),
    meta:{
      title:'注册',
      isbackshow:true,
      pageshow:false,
      search:false

    }
  },
  {
    path: '/goodslist/:keyword*',
    props:true,
    name: 'goodsdetail',
    component: goodlist,
    meta:{
      title:'商品列表',
      pageshow:false,
      search:true,
      isbackshow:true

    }
  },
  {
    path: '/liannew',
    name: 'liannew',
    component: liannew,
    meta:{
      title:'青恋新闻',
      pageshow:false,
      isbackshow:true

    }
  },
  {
    path: '/seeplove',
    name: '青恋',
    component: foundlove,
    meta:{
      title:'青恋',
      isbackshow:false,
      authority:true
    }
  },
  {
      
    path: '/newsDetails/:id',
    props:true,
    name: 'newtail',
    component: newtail,
    meta:{
      title:'新闻详情',
      pageshow:false,
      isbackshow:true,

    }

  }
  ,
  {
    path: '/friends',
    name: '好友',
    component: friends,
    meta:{
      title:'好友',
      isbackshow:false,
      authority:true
    }
  },
  {
    path: '/gooddetails/:id',
    name: '商品详情',
    props:true,
    component: ()=> import ('@/views/goodsdetail.vue') ,
    meta:{
      title:'商品详情',
      isbackshow:true,
      pageshow:false,
      authority:true
    }
  },



  {
    path: '/shopcar/:back*',
    props:true,
    name: '购物车',
    component: () => import(/*购物车*/ '../views/shopcar.vue' ),
    meta:{
      title:'购物车',
      nokeeplive:true

    }
  },
  {
    path: '/user',
    name: 'User',
    meta:{
      title:'个人中心',
      isbackshow:false,
      authority:true
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/order',
    name: 'order',
    meta:{
      title:'全部订单',
      isbackshow:false,
      authority:true
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/order.vue')
  },
  {
    path: '/address/:fromshop*',
    props:true,
    name: 'address',
    meta:{
      title:'管理地址',
      isbackshow:true,
      authority:true
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/address.vue')
  },
  {
    path: '/addAddress',
    name: 'addAddress',
    meta:{
      title:'添加地址',
      isbackshow:true,
      authority:true
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/addAddress.vue')
  },
  {
    path: '/editAddress/:addressInfo',
    props:true,
    name: 'editAddress',
    meta:{
      title:'编辑地址',
      isbackshow:true,
      authority:true,
      nokeeplive:true
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/editaddress.vue')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from,next) => {

  if( to.meta.authority && store.getters.gettoken == ""){
    store.commit("chantsaverouter",to.fullPath)
      next({path:"/login"});
      return;
  }
  next();
  return false
})

export default router
